package com.ruoyi.web.controller.devops;

import java.util.List;
import java.util.UUID;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.devops.domain.DevOpsEnvInfo;
import com.ruoyi.devops.service.IDevOpsEnvInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 环境管理Controller
 * 
 * @author ruoyi
 * @date 2023-01-26
 */
@Controller
@RequestMapping("/devops/env")
public class DevOpsEnvInfoController extends BaseController
{
    private String prefix = "devops/env";

    @Autowired
    private IDevOpsEnvInfoService devOpsEnvInfoService;

    @RequiresPermissions("devops:env:view")
    @GetMapping()
    public String env()
    {
        return prefix + "/env";
    }

    /**
     * 查询环境管理列表
     */
    @RequiresPermissions("devops:env:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DevOpsEnvInfo devOpsEnvInfo)
    {
        startPage();
        List<DevOpsEnvInfo> list = devOpsEnvInfoService.selectDevOpsEnvInfoList(devOpsEnvInfo);
        return getDataTable(list);
    }

    /**
     * 导出环境管理列表
     */
    @RequiresPermissions("devops:env:export")
    @Log(title = "环境管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DevOpsEnvInfo devOpsEnvInfo)
    {
        List<DevOpsEnvInfo> list = devOpsEnvInfoService.selectDevOpsEnvInfoList(devOpsEnvInfo);
        ExcelUtil<DevOpsEnvInfo> util = new ExcelUtil<DevOpsEnvInfo>(DevOpsEnvInfo.class);
        return util.exportExcel(list, "环境管理数据");
    }

    /**
     * 新增环境管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存环境管理
     */
    @RequiresPermissions("devops:env:add")
    @Log(title = "环境管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DevOpsEnvInfo devOpsEnvInfo)
    {
        devOpsEnvInfo.setUuid(UUID.randomUUID().toString());
        return toAjax(devOpsEnvInfoService.insertDevOpsEnvInfo(devOpsEnvInfo));
    }

    /**
     * 修改环境管理
     */
    @RequiresPermissions("devops:env:edit")
    @GetMapping("/edit/{uuid}")
    public String edit(@PathVariable("uuid") String uuid, ModelMap mmap)
    {
        DevOpsEnvInfo devOpsEnvInfo = devOpsEnvInfoService.selectDevOpsEnvInfoByUuid(uuid);
        mmap.put("devOpsEnvInfo", devOpsEnvInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存环境管理
     */
    @RequiresPermissions("devops:env:edit")
    @Log(title = "环境管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DevOpsEnvInfo devOpsEnvInfo)
    {
        return toAjax(devOpsEnvInfoService.updateDevOpsEnvInfo(devOpsEnvInfo));
    }

    /**
     * 删除环境管理
     */
    @RequiresPermissions("devops:env:remove")
    @Log(title = "环境管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(devOpsEnvInfoService.deleteDevOpsEnvInfoByUuids(ids));
    }
}
